<?PHP
    $redis_cluster = [
        '192.168.88.11:6379',
        '192.168.88.12:6379',
        '192.168.88.13:6379',
        '192.168.88.14:6379',
        '192.168.88.15:6379',
        '192.168.88.16:6379'
    ];
    $redis = new RedisCluster(NULL, $redis_cluster);
    $time = $redis->get('time');

    if(empty($time)){
        echo "Query From \033[31mMySQL\033[0m:\t";
        $mysqli = new mysqli('127.0.0.1','root','','mysql');
        if (mysqli_connect_errno()){
                die('Unable to connect!'). mysqli_connect_error();
        }
        $sql = "SELECT time(now())";
        $result = $mysqli->query($sql);
        $rs = $result->fetch_array();
        $r=$rs[0];
        $redis->set("time",$r);
        $redis->expire("time",5);
        echo "$r";
        echo "\n";
    }else{
        echo "Query From \033[32mRedis\033[0m:\t";
        echo $time;
        echo "\n";
    }
?>
